<?php
/**
 * @author tungck
 * @filesource chamcong_model.php
 * file model for process position manager
*/
?>

<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class chamcong_model extends CI_Model{
    
    public $tableName = 'chamcong';
    
    function __construct(){
        parent::__construct();
        $this->load->helper('url');
        $this->load->database();
        
    }
    
    // lay danh sách vi tri chuc danh
    function getList($data){
        $recordCount = $this->db->count_all_results('chamcong');
        if($data['filter'] != '0'){
        $query = $this->db->query("SELECT * FROM chamcong WHERE MaHoSo=".$data['filter']." ORDER BY " . $data['sort'] . " LIMIT " . $data['startIndex'] . "," . $data['pageSize'] . ";");
        }else{
            $query = $this->db->query("SELECT * FROM chamcong ORDER BY " . $data['sort'] . " LIMIT " . $data['startIndex'] . "," . $data['pageSize'] . ";");
        }
        if($query){
            $result['query'] = $query->result();
            $result['recordCount'] = $recordCount;
            return $result;
        }else{
            return false;
        }
        
    }
    
    function getAll(){
        $query = $this->db->query("SELECT * FROM chamcong");
        if($query){
            return $query->result();
        }else{
            return false;
        }
        
    }
    
    function getById($id){
        $query = $this->db->query("SELECT TenBoPhan FROM chamcong WHERE MaBoPhan = ".$id);
        if($query){
            return $query->result();
        }else{
            return false;
        }
        
    }
    
    function them_cham_cong($data){
        $this->db->insert('chamcong', $data);
        $query = $this->db->get_where('chamcong', 'MaChamCong = LAST_INSERT_ID()');
        if($query){
            return $query->result();
        }else{
            return false;
        }
    }
    
    function xoa_cham_cong($id){
        $this->db->delete('chamcong', array('MaChamCong'=>$id));
    }
    
    function thay_doi_cham_cong($data){
        $this->db->where('MaChamCong', $data['MaChamCong']);
        $this->db->update('chamcong', $data); 
    }
    
}

?>